#!/usr/bin/env bash

#颜色变量
Green="\033[32m"
Red="\033[31m"
Yellow="\033[43;37m"
blue="\033[44;37m"
GreenBG="\033[42;37m"
RedBG="\033[41;37m"
Font="\033[0m"

#获取脚本方式
download="curl -O -L"

#检查账号权限
check_root(){
	if [[ $EUID != 0 ]];then
		echo -e "${RedBG}当前不是ROOT账号，建议更换ROOT账号使用。${Font}\n"
		sleep 5
	else
		echo -e "${GreenBG}ROOT权限检查通过，欢迎您的使用！${Font}\n"
		sleep 2
	fi
}

#检查软件源
epel_install(){
        echo 'epel软件源 后台安装中'
    if [[ $release == "CentOS" ]];then
	    yum install epel-release -y
	elif [[ $release == "Debian" ]] || [[ $release == "Ubuntu" ]];then
	    apt-get install epel-release -y
	else
		echo 'epel软件源 后台安装失败'
	fi
}

#安装依赖
sys_install(){
        echo 'epel软件源 后台安装中'
    if ! type curl >/dev/null 2>&1; then
        echo 'curl 未安装 正在安装中'
	    apt-get install curl -y || yum install curl -y
    else
        echo 'curl 已安装，继续操作'
    fi

    if ! type wget >/dev/null 2>&1; then
        echo 'wget 未安装 正在安装中';
	    apt-get install wget -y || yum install wget -y
    else
        echo 'wget 已安装，继续操作'
    fi
}

#核心文件
get_opsy(){
    [ -f /etc/redhat-release ] && awk '{print ($1,$3~/^[0-9]/?$3:$4)}' /etc/redhat-release && return
    [ -f /etc/os-release ] && awk -F'[= "]' '/PRETTY_NAME/{print $3,$4,$5}' /etc/os-release && return
    [ -f /etc/lsb-release ] && awk -F'[="]+' '/DESCRIPTION/{print $2}' /etc/lsb-release && return
}

#变量引用
opsy=$( get_opsy )
cores=$( awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo )
tram=$( free -m | awk '/Mem/ {print $2}' )
uram=$( free -m | awk '/Mem/ {print $3}' )
ipv4=$(curl -s myip.ipip.net | awk -F ' ' '{print $2}' | awk -F '：' '{print $2}')
#ipaddr=$(curl -s myip.ipip.net | awk -F '：' '{print $3}')

#脚本菜单
Menu(){
    echo -e "${GreenBG}---Linux综合脚本---${Font}\n"
#显示系统信息
    echo -e "本机操作系统${Green} $opsy ${Font}"
    echo -e "本机CPU${Green} $cores ${Font}核，系统内存${Green} $tram ${Font}MB"
    echo -e "本机IP地址${Green} $ipv4 ${Font}\n"
    
    echo -e "${Green}11.${Font} VPS信息和性能测试"
    echo -e "${Green}12.${Font} Bench系统综合测试"
    echo -e "${Green}13.${Font} Linux系统实用功能"
    echo
    echo -e "${Green}21.${Font} 设置/删除-交换内存"
    echo -e "${Green}22.${Font} 自助修改服务器DNS"
    echo -e "${Green}23.${Font} 流媒体区域限制测试"
    echo -e "${Green}24.${Font} 安装/启用BBR-TCP加速"
    echo -e "${Green}25.${Font} Linux网络重装dd系统"
    echo
    echo -e "${Green}31.${Font} frps服务端-管理脚本"
    echo -e "${Green}32.${Font} frps客户端-管理脚本"
    echo -e "${Green}33.${Font} Nezha哪吒监控-云探针"
    echo -e "${Green}34.${Font} ServerStatus-云探针"
    echo -e "${Green}35.${Font} 端口转发"
    echo
    echo -e "${Green}99.${Font} 退出当前脚本\n"

    read -rp "请输入对应的数字：" num
    case $num in
    11)
        ${download} https://gitee.com/hbwzy/linux-collection-script/raw/master/xncs.sh && chmod +x xncs.sh && bash xncs.sh
        ;;
    12)
        ${download} https://gitee.com/hbwzy/linux-collection-script/raw/master/bench.sh && chmod +x bench.sh && bash bench.sh
        ;;
    13)
        ${download} https://gitee.com/hbwzy/linux-collection-script/raw/master/tools.sh && chmod +x tools.sh && bash tools.sh
        ;;
    21)
        ${download} https://gitee.com/hbwzy/linux-collection-script/raw/master/swap.sh && chmod +x swap.sh && bash swap.sh
        ;;
    22)
        ${download} https://gitee.com/hbwzy/linux-collection-script/raw/master/dns.sh && chmod +x dns.sh && bash dns.sh
        ;;
    23)
        ${download} https://gitee.com/hbwzy/linux-collection-script/raw/master/check.sh && chmod +x check.sh && bash check.sh
        ;;
    24)
        ${download} https://gitee.com/hbwzy/linux-collection-script/blob/master/tcp.sh && chmod +x tcp.sh && bash tcp.sh
        ;;
    25)
        ${download} https://gitee.com/hbwzy/linux-collection-script/raw/master/Network-Reinstall-System-Modify.sh && chmod a+x Network-Reinstall-System-Modify.sh && bash Network-Reinstall-System-Modify.sh -UI_Options
        ;;
    31)
        ${download} https://gitee.com/hbwzy/linux-collection-script/raw/master/frps.sh && chmod +x frps.sh && bash frps.sh
        ;;
    32)
        ${download} https://gitee.com/hbwzy/linux-collection-script/raw/master/frpc.sh && chmod +x frpc.sh && bash frpc.sh
        ;;
    33)
        ${download} https://gitee.com/hbwzy/linux-collection-script/raw/master/nezha.sh && chmod +x nezha.sh && bash nezha.sh
        ;;
    34)
        ${download} https://gitee.com/hbwzy/linux-collection-script/blob/master/status.sh && chmod +x status.sh && bash status.sh
        ;;
    35)
        ${download} https://gitee.com/hbwzy/linux-collection-script/raw/master/dkzf.sh && chmod +x dkzf.sh && bash dkzf.sh
        ;;
    99)
        echo -e "\n${GreenBG}感谢您的使用${Font}\n" && exit
        ;;
    *)
        echo -e "\n${RedBG}请输入正确的数字！${Font}\n" && sleep 2 && start_linux
        ;;
    esac
}

#脚本启动
check_root
epel_install >/dev/null 2>&1 &
sys_install
echo
Menu